package com.yixun.qfbao.hander;

import com.yixun.qfbao.model.enums.SystemIdEnum;
import com.yixun.qfbao.util.WxAccessTokenCacheUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yixun.qfbao.api.service.CPFollowUPService;
import com.yixun.qfbao.apidto.AddFollowReqDto;
import com.yixun.qfbao.apidto.AddFollowResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.util.exception.TServerException;
import com.yixun.qfbao.vo.AddFollowReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;

/**
 *（26）	报备跟进新增 
 * @author xiaojin.li
 *
 */
@Service("addFollowHander")
public class AddFollowHander extends CommonAbstractHander {
	private static Logger logger= LoggerFactory.getLogger(AddFollowHander.class);
	
	@Autowired
	private CPFollowUPService cpFollowUPService;
	@Autowired
    private WxAccessTokenCacheUtils wxAccessTokenCacheUtils;

	@Override
	public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
		AddFollowReqVo req = (AddFollowReqVo)reqDto;
		AddFollowReqDto reqDto1 = req.getParams();
		BaseResponseDTO<AddFollowResDto> res = new BaseResponseDTO<AddFollowResDto>();
		AddFollowResDto resDto = new AddFollowResDto();
		try {
            //获取案场助手的微信accessToken
            String assistantAccessToken = wxAccessTokenCacheUtils.getAccessToken(reqDto1.getCompanyUuid(), SystemIdEnum.ASSISTANT.getCode(), reqDto1.getDomain());
            reqDto1.setAssistantAccessToken(assistantAccessToken);
            resDto = cpFollowUPService.addFollow(reqDto1);
		}catch(TServerException e){
			resDto.setResult(ResultEnum.FAIL.getNo());
			resDto.setResultMsg(e.getErrorMsg());
		} catch (Exception e) {
			logger.error("AddFollowHander error: {}", e);
			resDto.setResult(ResultEnum.FAIL.getNo());
			resDto.setResultMsg("系统异常");
		}
		res.setResData(resDto);
		res.setResult(resDto.getResult());
		return res;
	}
	
}
